<template>
	<view class="main">
		<view class="box">
			<view class="part">
				<view class="txt">编号：</view>
				<input class="input"  type="text" v-model="cid"/>
			</view>
			<view class="part">
				<view class="txt">姓名：</view>
				<input class="input"  type="text" v-model="cname"/>
			</view>
			<view class="part">
				<view class="txt">性别：</view>
				<radio-group>
					<radio class="radio" :checked="man" @tap="manclick">男</radio>
				    <radio class="radio" :checked="woman" @tap="womanclick">女</radio>
				</radio-group>
				
			</view>
			
			<view class="part">
				<view class="txt">电话：</view>
				<input class="input"  type="text" v-model="cphone"/>
			</view>
			<view class="part">
				<view class="txt">地址：</view>
				<input class="input"  type="text" v-model="caddress"/>
			</view>
			<view class="part">
				<view class="txt">年龄：</view>
				<input class="input"  type="text" v-model="cage"/>
			</view>
			
			<view class="part1">
				
			</view>
			
			<button type="primary" @tap='clicksave'>保存</button>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				cid:'',
				cname:'',
				csex:'',
				cphone:'',
				caddress:'',
				cage:'',
				man:false,
				woman:false
			}
		},
		
		onLoad() {
			uni.$on('sendcustomerid',(data)=>{
				uni.request({
					url: this.url+'customer/getone',
					method: 'GET',
					data: {
						cid:data.cid
					},
					success: res => {
						this.cid = res.data.data.c_id;
						this.cname = res.data.data.c_name;
						if(res.data.data.c_sex ==1){this.man = true;this.woman=false;}
						else{this.man=false;this.woman=true}
						
						this.cphone = res.data.data.c_phone;
						this.caddress = res.data.data.c_address;
						this.cage = res.data.data.c_age;
					},
					fail: () => {},
					complete: () => {}
				});
				
				
			})
		},
		onUnload() {
			uni.$off('sendcustomerid');
		},
		methods: {
			manclick(){
				this.csex = 1;
			},
			womanclick(){
				this.csex = 0;
			},
			clicksave(){
				uni.request({
					url: this.url+'customer/updateone',
					method: 'GET',
					data: {
						cid:this.cid,
						cname:this.cname,
						csex:this.csex,
						cphone:this.cphone,
						caddress:this.caddress,
						cage:this.cage
					},
					success: res => {
						console.log(res);
					},
					fail: () => {},
					complete: () => {}
				});
			}
	
		}
	}
</script>

<style>
	.radio{
		width: 100rpx;
	}
	.input{
		width: 80%;
		font-size: large;
		height: 100%;
		
	}
	.txt{
		font-size: large;
		width: 20%;
		display: flex;
		flex-direction: column;
		justify-content: center;
	}
	.part{
		display: flex;
		justify-content: center;
		width: 100%;
		height: 50px;
		border-bottom: #C0C0C0 1px solid;
		
	}
	.part1{
		width: 100%;
		height: 50px;
	}	
	.box{
		width: 90%;
		height: 300px;

	}
	.main{
		display: flex;
		justify-content: center;
		width: 100%;
	}

</style>
